home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / converter / limbo4.0 / src / 2d / decode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  4.1 KB  |  123 lines

  1. #include "includes.h"
  2.  
  3.  int Decode_Flag;
  4.  BitMap *Decode_Block1;
  5.  BitMap *Decode_Block2;
  6.  BitMap *Decode_Image;
  7.  
  8. /**************************************|****************************************
  9. Routine   :DecodeTrans3D
  10. Input  par:Transformation *Trans (pointer to transformation to be decoded)
  11.            int XPos,int YPos,int ZPos (xy and z position in image of trans)
  12.            unsigned int LLevel (expansion level)
  13. Output par:none
  14. Function  :Takes a singel transformation and decodes it to an image block.
  15. ***************************************|***************************************/
  16.  
  17.  void DecodeTrans(Transformation *Trans,int XPos,int YPos,unsigned int LLevel)
  18.   {
  19.    Decode_Block1->XSize=Decode_Block1->YSize=Trans->BlockSize<<LLevel;
  20.    Decode_Block2->XSize=Decode_Block2->YSize=Trans->BlockSize<<LLevel;
  21.    
  22.    switch(Trans->Type)
  23.     {
  24.      case EDGEBLOCK:
  25.      
  26.      Sample(Decode_Image,Decode_Block1,(Trans->Domain->x)<<LLevel,
  27.              (Trans->Domain->y)<<LLevel);
  28.      T_CScaleAndLShift(Decode_Block1,Trans->Alpha,Trans->Deltag);
  29.      Isometri(Decode_Block1,Decode_Block2,Trans->tn+1);
  30.      BitMap2Map(Decode_Block2,Decode_Image,(XPos<<LLevel),
  31.                     (YPos<<LLevel));
  32.      break;
  33.      case SHADEBLOCK:
  34.      if (Decode_Flag)
  35.       {
  36.        T_AbsorbGrey(Decode_Block1,(unsigned char)Trans->g0);
  37.        BitMap2Map(Decode_Block1,Decode_Image,(XPos<<LLevel),
  38.                       (YPos<<LLevel));
  39.       }
  40.      break;
  41.      case NOBLOCK:
  42.      break;
  43.      default: ErrorHandler(OUT_OF_RANGE,"Unknown block type in Decode");
  44.      break;
  45.     }
  46.    
  47.    if(Trans->Sub)
  48.     {
  49.      register unsigned int i,j;
  50.      for(i=0;i<2;i++)
  51.      for(j=0;j<2;j++)
  52.      if(Trans->Sub[i][j])
  53.      DecodeTrans(Trans->Sub[i][j],XPos+(i*(Trans->Sub[i][j]->BlockSize))
  54.                    ,YPos+(j*(Trans->Sub[i][j]->BlockSize)),
  55.                    LLevel);
  56.     }
  57.   }
  58.  
  59. /**************************************|****************************************
  60. Routine   :Decode3D
  61. Input  par:Transformation ****FCCodes (FCCodes to be decoded)
  62.            int ImgType (image type)
  63.            int xsize, int ysize, int zsize (image size)
  64.            int StartBlockSize (maximum block size)
  65.            int Iterations (iterateions)
  66.            int LLevels (expand at llevels)
  67. Output par:*BitMap3D (pointer to a 3d bitmap)
  68. Function  :Decodes an array of fccodes to a bitmap structure.
  69. ***************************************|***************************************/
  70.  
  71.  BitMap *Decode(Transformation ***FCCodes,int ImgType, int xsize, int ysize,
  72.                   int StartBlockSize, int Iterations, int LLevels)
  73.   {
  74.    register int i,j,l;
  75.    
  76.    vprintf(stderr,"\nDecoding...");
  77.    
  78.    Decode_Flag=TRUE;
  79.    Decode_Block1=GimmeABitMap(StartBlockSize,StartBlockSize,ImgType);
  80.    Decode_Block2=GimmeABitMap(StartBlockSize,StartBlockSize,ImgType);
  81.    Decode_Image=GimmeABitMap(xsize,ysize,ImgType); /* LoadBitMap("teach2",xsize,ysize,0,,1,ORGGFX);*/
  82.    
  83.    for (l=0;l<Iterations;l++) /* decode iterations */
  84.     {
  85.      for (i=0;i<xsize/StartBlockSize;i++)
  86.      for (j=0;j<ysize/StartBlockSize;j++)
  87.      DecodeTrans(FCCodes[i][j],i*StartBlockSize,j*StartBlockSize,0);
  88.  
  89.      Decode_Flag=FALSE;
  90.      if (Quiet) fprintf(stderr,".");
  91.      else fprintf(stderr,"\n   (%d/%d)",l+1,Iterations);
  92.     }
  93.    
  94.    if (LLevels) /* expansion iterations */
  95.     {
  96.      Decode_Block1->XSize=Decode_Block1->YSize=StartBlockSize;
  97.      Decode_Block2->XSize=Decode_Block2->YSize=StartBlockSize;
  98.      
  99.      for (l=1;l<LLevels+1;l++) 
  100.       {
  101.        Decode_Block1=Expand2(Decode_Block1);
  102.        Decode_Block2=Expand2(Decode_Block2);
  103.        Decode_Image=Expand2(Decode_Image);
  104.        for (i=0;i<xsize/StartBlockSize;i++)
  105.         {
  106.          for (j=0;j<ysize/StartBlockSize;j++)
  107.          DecodeTrans(FCCodes[i][j],i*StartBlockSize,
  108.                        j*StartBlockSize,l);
  109.          }
  110.        if (Quiet) fprintf(stderr,",");
  111.        else fprintf(stderr,"\n   [%d/%d]",l,LLevels);
  112.       }
  113.     }
  114.   
  115.    Decode_Block1->XSize=Decode_Block1->YSize=StartBlockSize;
  116.    Decode_Block2->XSize=Decode_Block2->YSize=StartBlockSize;
  117.    FreeMeABitMap(Decode_Block1);
  118.    FreeMeABitMap(Decode_Block2);
  119.    
  120.    return Decode_Image;
  121.   }
  122.  
  123.